<html>
<head>
<title>管理系统</title>
<meta http-equiv=Content-Type content=text/html;charset=utf-8>
<#include "../inc/commonJs.html">
<script type="text/JavaScript">
	var flgrid, flid;
	var flmxgrid;
	$(function() {
	// 折叠 south
	$('#body').layout('collapse','south');
	//分类管理表格  
	flgrid = $('#flgrid').datagrid({
        url:'listFl.do',  
        loadMsg:'数据加载中请稍后……',  
        striped: true,  
        singleSelect : true,  
        pagination: true,  
        rownumbers: true, 
        pageSize: [${syscfg.pageSize!10}],
        pageList: [${syscfg.pageList!10}],
         columns:[[  
             {field:'flid',title: '分类ID',align: 'center',width: '100'}, 
             {field:'fldm',title: '分类代码',align: 'center',width: '100'},
             {field:'flmc',title: '分类名称',align: 'center',width: '200'},
             {field:'flmx',title: '分类明细',align: 'center',width: '150',
            	 formatter : function(value, rowdata,index) {
         			//var flid = $('#flgrid').datagrid('getData').rows[rowIndex].flid;
         			var str = '<a id="btnadd" class="l-btn l-btn-plain" href="javascript:showFlmx(\''+value+'\')"><span class="l-btn-left"><span class="l-btn-text icon-search l-btn-icon-left">显示明细</span></span></a>';
         			return str;
				}
			}
         ]],
         toolbar : [btn_add,btn_edit,btn_del,"-"]
    });
	//
    flgrid.datagrid({
		onDblClickCell: function(rowIndex,rowData){
			var flid = $('#flgrid').datagrid('getData').rows[rowIndex].flid;
			showFlmx(flid);
		}
	});
	// 
	$('#south').panel({
		height: $('#body').height()/2,
		onCollapse: function() {
			$('#south').attr('collapse',true);
		}
	});
	//明细管理表格
    flmxgrid = $('#flmxgrid').datagrid({
        url:'listFlmx.do',  
        loadMsg:'数据加载中请稍后……',  
        striped: true,  
        singleSelect : true,  
        pagination: true,  
        rownumbers: true, 
        columns:[[  
             {field:'mxid',title: '明细ID',align: 'center',width: '100'},  
             {field:'mxdm',title: '明细代码',align: 'center',width: '100'},
             {field:'mxmc',title: '明细名称',align: 'center',width: '100'},
             {field:'fid',title: '上级明细',align: 'center',width: '100',
             formatter : function(value, rowdata,index) {
	             	if(value==0){
	             		return ''
	             	}else{
						return value;
	             	}
				}
			},
             {field:'flmc',title: '所属分类',align: 'center',width: '100'},
             {field:'px',title: '排序',align: 'center',width: '100'},
             {field:'zt',title: '状态',align: 'center',width: '100',
             	formatter: function(value,rowdata,index){
             		var str = '';
					if(value ==1){
						str += '<a id="btnstate" class="l-btn l-btn-plain" href="javascript:jinyong('+rowdata.mxid+','+rowdata.zt+')"><span class="l-btn-left"><span class="l-btn-text icon-ok l-btn-icon-left">禁用</span></span></a>';
					}else{
						str += '<a id="btnstate" class="l-btn l-btn-plain" href="javascript:jinyong('+rowdata.mxid+','+rowdata.zt+')"><span class="l-btn-left"><span class="l-btn-text icon-no l-btn-icon-left">启用</span></span></a>';
					}
					return str;
				}
             } 
         ]],
         toolbar : '#toolbar'
     });
});
	function showFlmx(flid) {
		if($('#south').attr('collapse')=="true"){
			$('#south').attr('collapse',false);
			$('#body').layout(); 
			$('#body').layout('expand','south');
		}
		$('#flid').val(flid);
		$('#flmxgrid').datagrid('reload',{'flid': flid});
	}
	//新增分类管理
	function doAdd() {
		var url = '${request.contextPath}/xadmin/system/flWindow.do';
		top.modalwindow(url, flgrid,{ width:500,height:160,title:'分类管理设置'});
	}
	//工具栏修改分类管理
	function doEdit(flid) {
		var selected = flgrid.datagrid('getSelected');
		if(!selected){
			$.messager.alert('提示',"请选择相关数据进行操作！");
			return;
		}		
		var url = '${request.contextPath}/xadmin/system/flWindow.do?flid='+selected.flid;
		top.modalwindow(url, flgrid,{ width:500,height:160,title:'分类管理设置'});
	}
	//工具栏删除分类管理
	function doDel(){
		var selected = flgrid.datagrid('getSelected');
		if(!selected){
			$.messager.alert('提示',"请选择相关数据进行操作！");
			return;
		}
		$.messager.confirm('系统提示', '<br>&nbsp;&nbsp;&nbsp;&nbsp;你确定要删除该信息?', function(r) {
			if (r) {
				$.post("delFl.do", { "flid": selected.flid},
				   function(data){
				   	flgrid.datagrid('reload'); 
				    top.messagershow(data);
				});
			}
		});
	}
	//新增明细管理
	function addMx() {
		var url = '${request.contextPath}/xadmin/system/flmxWindow.do?flid='+$('#flid').val();
		top.modalwindow(url, flmxgrid,{ width:500,height:300,title:'明细管理设置'});
	}
	//工具栏修改明细管理
	function editMx() {
		var selected = flmxgrid.datagrid('getSelected');
		if(!selected){
			$.messager.alert('提示',"请选择相关数据进行操作！");
			return;
		}
		//
		var url = '${request.contextPath}/xadmin/system/flmxWindow.do?flid='+$('#flid').val()+'&mxid='+selected.mxid;
		top.modalwindow(url, flmxgrid ,{ width:500,height:300, title:'明细管理设置'});
	}
	//工具栏删除明细管理
	function delMx(){
		var selected = flmxgrid.datagrid('getSelected');
		if(!selected){
			$.messager.alert('提示',"请选择相关数据进行操作！");
			return;
		}
		$.messager.confirm('系统提示', '<br>&nbsp;&nbsp;&nbsp;&nbsp;你确定要删除该信息?', function(r) {
			if (r) {
				$.post("delFlmx.do", { "mxid": selected.mxid},
				   function(data){
				   	flmxgrid.datagrid('reload'); 
				   	top.messagershow(data);				   	
				});
			}
		});
	}
	//审核
	function jinyong(mxid,state){
		if(state==0){
			state = 1;
		}else{
			state = 0;
		}
		$.post("updateMxState.do", { "mxid":mxid, "state":state},
		   	function(data){
		   		flmxgrid.datagrid('reload'); 
		   		top.messagershow(data);
		});
	}	
</script>
</head>
<body id="body" class="easyui-layout">
	<div data-options="region:'center',title:'分类管理',split:true" >
		<table id="flgrid" data-options="fit:true,border:false"></table>
	</div>   
    <div id="south" class="easyui-panel" data-options="region:'south',title:'明细管理',split:true" collapse=true>
	    <table id="flmxgrid" data-options="fit:true,border:false"></table>
    </div> 
<div id="toolbar" style="display: none;">
<table border="0" cellpadding="0" cellspacing="0"><tr>
	<td valign="center" align="left">
	<a href="javascript:addMx();" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true">增加</a>
	</td>
	<td valign="center" align="left">
	<a href="javascript:editMx();" class="easyui-linkbutton" data-options="iconCls:'icon-edit',plain:true">修改</a>
	</td>
	<td valign="center" align="left">
	<a href="javascript:delMx();" class="easyui-linkbutton" data-options="iconCls:'icon-cancel',plain:true">删除</a>
	</td>
	<td valign="center">
	<div class="datagrid-btn-separator"></div>
	</td>
</tr></table>
<input type="hidden" name="flid" id="flid" value="0">
</div>
</body>
</html>